package com.example.service;


import com.example.entity.Admin;
import com.example.entity.Student;
import com.example.mapper.AdminMapper;
import com.example.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
     @Autowired
     private StudentMapper studentMapper;
    @Autowired
    private AdminMapper adminMapper;

    public UserService(StudentMapper studentMapper, AdminMapper adminMapper) {
        this.studentMapper = studentMapper;
        this.adminMapper = adminMapper;
    }

    public Student loginStudent(String stu_num, String password) {
        Student student = studentMapper.getStudentByUsername(stu_num);

        if (student != null && student.getPassword().equals(password)) {
            return student;
        } else {
            throw new RuntimeException("用户名或密码错误");
        }
    }

    public Admin loginAdmin(String admin_num, String password) {
        Admin admin = adminMapper.getAdminByUsername(admin_num);

        if (admin != null && admin.getPassword().equals(password)) {
            return admin;
        } else {
            throw new RuntimeException("用户名或密码错误");
        }
    }
}
